<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>找回密码</title>
        <link rel="Stylesheet" href="css/style1.css" type="text/css">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  
  
    <jsp:useBean id="data" class="org.database.DatabaseTool" scope="application" />
     <% 
     
      String username=request.getParameter("username");
      String recordinfo=request.getParameter("recordinfo");
      String newpassword=request.getParameter("newpassword");
      if(newpassword!=null&&recordinfo!=null){
      String record=(String)session.getAttribute("recordinfo");
      String user=(String)session.getAttribute("username");
      boolean result=data.updatePassword(newpassword,record,user);
      if(result){
         out.print("<script>alert('修改密码成功');document.location='/MyChat/servlet/UserServlet'</script>");
      }else{
         out.print("<script>alert('修改密码失败');document.location='/MyChat/servlet/UserServlet'</script>");
      }
      }else{
      if(username!=null&&recordinfo!=null){
      session.setAttribute("recordinfo",recordinfo);
      session.setAttribute("username",username);
        String password=data.retrievePassword(recordinfo, username); 
        if(password!=null){
        %>
         <body bgcolor="#f8f8f8">
    <div class="content center">
    <div  style="margin:100px auto;background-color:#fff;border: 2px solid #fff;width:400px;height:300px;">
        <div style="width: 280px;margin: 60px auto;position: relative">
          <form method="post" action="findresult.jsp">  
           <input type="password" name="password" placeholder="新密码" autocomplete="off" autofocus="autofocus" required="required">
         <input type="password" name="newpassword" placeholder="确认密码" autocomplete="off" autofocus="autofocus" required="required">
         <input type="hidden" name="recordinfo" value="<%=recordinfo%>">
       <button type="submit">修改密码</button>
       </form>
        </div>
        </div>
        </div>
             <div style="margin-top:150px;"><%@include file="footer.jsp" %></div>
        <% 
        }else{
         out.print("<script>alert('请输入正确的用户名和关键词');document.location='/MyChat/retrievePassword.jsp'</script>");
        }
      }else{
      out.print("<script>alert('请输入输入用户名和关键词');document.location='/MyChat/retrievePassword.jsp'</script>");
      }}
     %>
  </body>
</html>
